package net.flyinggroup.kafka.fromroute.updated;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;

import java.util.function.Consumer;
import java.util.function.Function;

@SpringBootApplication
public class SourceWithDynamicDestination {

    public static void main(String[] args) {
        SpringApplication.run(SourceWithDynamicDestination.class,
                "--spring.cloud.function.definition=even;upperCase");
    }

    @Bean
    public Consumer<String> even() {
        return value -> System.out.println("Even:" + value);
    }

    @Bean
    public Function<String, Message<String>> upperCase() {
        return value -> MessageBuilder.withPayload(value)
                .setHeader("spring.cloud.stream.sendto.destination", value).build();
    }
}
